*This is a replication do file for "Public water waste reporting: contextual correlates and conservation outcomes"
*Water Resources Research
*Author: Y. Zhang, M.P. Teodoro, and D. Switzer
*macOS Big Sur, STATA 16,


use "2020 ZhangTeodoroSwitzer WRR drought reporting replication data.dta", clear


*create variable labels
label var ComplaintsReceived "Complaints received"
label var private "Private water utility"
label var Spdist "Special district"
label var StatemandatedConservationStan "% Conservation standard"
label var CALCULATEDRGPCDReportingMont "R-GPCD in reporting month"
label var  groundw "Ground water"                  
label var purchasedwater "Purchased water"
label var log_pop "Total population served logged"
label var WaterDaysAllowedWeek  "Water days allowed per week"
label var PerctBach "Percent bachelor"
label var PerctPov  "Percent poverty"
label var PerctBlack  "Percent black"
label var PerctHisp  "Percent Hispanic"
replace medianincomehouse_1000=MedianInc/1000
label var medianincomehouse_1000 "Median income house (1000s)"
label var ResidentialUse  "% Residential Use"
label var DemocraticInteraction "Democratic interaction index"

*net from https://www.sealedenvelope.com/
xfill StatemandatedConservationStan2, i(id)
gen Density2=Density*Density





*descriptive statistics (Table 1)
tab  ReportingMonth if WaterDaysAllowedWeek!=. 
tab  ReportingMonth if StatemandatedConservationStan>0
tab  ReportingMonth if ComplaintsReceived>0
tab ReportingMonth if ReportingMonth>=19950
tab ReportingMonth if ReportingMonth>=20254 & ReportingMonth<=20589
sum complaint_Per1000 Monthly_Con_percent Muni  Spdist party_comp_register  PercentTurnout   StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating            MeanMedRatio   Density   Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000 salience   if ReportingMonth>=19950 , sep(30)

corr medianincomehouse_1000 PerctBach  if ReportingMonth>=19950 & complaint_Per1000<=5
corr complaint_Per1000 Monthly_Con_percent Muni  Spdist party_comp_register PercentTurnout salience   MeanMedRatio   Density   Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000   StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             if ReportingMonth>=19950 & complaint_Per1000<=5

sum complaint_Per1000 Monthly_Con_percent Muni  Spdist party_comp_register PercentTurnout     StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating            MeanMedRatio   Density  Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000 salience   if ReportingMonth>=19950 & Muni==1, sep(30)
sum complaint_Per1000 Monthly_Con_percent Muni  Spdist party_comp_register  PercentTurnout   StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating PercentTurnout           MeanMedRatio   Density   Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000 salience   if ReportingMonth>=19950 & Spdist==1, sep(30)
sum complaint_Per1000 Monthly_Con_percent Muni  Spdist party_comp_register  PercentTurnout   StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating            MeanMedRatio   Density Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000 salience   if ReportingMonth>=19950 & Muni!=1 & Spdist!=1, sep(30)
by ReportingMonth, sort: sum ComplaintsReceived
 
 
 
 
 

*Main results (Table 2)
eststo clear

reg complaint_Per1000   StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating   i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5, cluster(PWSID) 
estimates store ModelA

reg complaint_Per1000  MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5, cluster(PWSID) 
estimates store ModelB

reg complaint_Per1000 Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5, cluster(PWSID) 
estimates store ModelC



coefplot (ModelA) , bylabel(Model A)  ||  (ModelB) , bylabel(Model B)   ||  (ModelC), bylabel(Model C)   ||,  coeflabels(Muni="Municipality"  Spdist="Special district" party_comp_register="Party competition" PercentTurnout="Percent turnout" salience="Monthly Google trend" MeanMedRatio="Mean-median income ratio"   Density="Population density"  Density2="Population density squared" Diversity="Ethnic diversity"   PercHisp="% Hispanic" PercBlack="% Black" PercAsian="% Asian"  PerctBach="% Bachelor degree"  PerctPov="% Income below poverty" medianincomehouse_1000="Median household income (1000s)"  StatemandatedConservationStan2="% State conservation standard" WaterDaysAllowedWeek="Water days allowed per week" ResidentialUse="% Residential use" groundw="Groundwater" purchasedwater="Purchased water" DMRating="Drought score" ) keep(Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating ) order(Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating) xline(0,lpattern(dash))  scheme(s2mono) graphregion(fcolor(white)) title("")  legend(off)   levels(95)  xscale(range(-0.2 0.2)) byopts(row(1))    groups(StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating = `""{bf:Utility}" "{bf:characteristics}""'   MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000 = `""{bf:Socioeconomic}" "{bf:factors}""'      Muni  Spdist party_comp_register PercentTurnout salience  = `""{bf:Political}" "{bf:factors}""')


test Muni=Spdist  





**Standardized coefficient plots (Figure 4)
preserve
center complaint_Per1000 Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating , inplace standardize
sum complaint_Per1000 Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating 
eststo clear

reg complaint_Per1000   StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating   i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5, cluster(PWSID) 
estimates store ModelA

reg complaint_Per1000  MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5, cluster(PWSID) 
estimates store ModelB

reg complaint_Per1000 Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5, cluster(PWSID) 
estimates store ModelC


coefplot (ModelA) , bylabel(Model A)  ||  (ModelB) , bylabel(Model B)   ||  (ModelC), bylabel(Model C)   ||,  coeflabels(Muni="Municipality"  Spdist="Special district" party_comp_register="Party competition" PercentTurnout="Percent turnout" salience="Monthly Google trend" MeanMedRatio="Mean-median income ratio"   Density="Population density" Density2="Population density squared" Diversity="Ethnic diversity"   PercHisp="% Hispanic" PercBlack="% Black" PercAsian="% Asian"  PerctBach="% Bachelor degree"  PerctPov="% Income below poverty" medianincomehouse_1000="Median household income (1000s)"  StatemandatedConservationStan2="% State conservation standard" WaterDaysAllowedWeek="Water days allowed per week" ResidentialUse="% Residential use" groundw="Groundwater" purchasedwater="Purchased water" DMRating="Drought score" ) keep(Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating ) order(Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating) xline(0,lpattern(dash))  scheme(s2mono) graphregion(fcolor(white)) title("")  legend(off)   levels(95)  xscale(range(-0.1 0.15)) byopts(row(1))  groups(StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating = `""{bf:Utility}" "{bf:characteristics}""'   MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000 = `""{bf:Socioeconomic}" "{bf:factors}""'      Muni  Spdist party_comp_register PercentTurnout salience  = `""{bf:Political}" "{bf:factors}""')




*Does reporting affect conservation? (Table 3; Figure 6)
*https://blog.stata.com/2015/11/12/xtabond-cheat-sheet/
xtset id time
eststo clear
*GMM
xtabond Monthly_Con_percent complaint_Per1000       WaterDaysAllowedWeek ResidentialUse  salience        DMRating   if ReportingMonth>=19950  ,  vce(robust)
estat abond

preserve
center Monthly_Con_percent complaint_Per1000       WaterDaysAllowedWeek ResidentialUse  salience        DMRating, inplace standardize
sum Monthly_Con_percent complaint_Per1000       WaterDaysAllowedWeek ResidentialUse  salience        DMRating

xtabond Monthly_Con_percent complaint_Per1000       WaterDaysAllowedWeek ResidentialUse  salience        DMRating   if ReportingMonth>=19950  ,  vce(robust)
estimates store ModelD

coefplot (ModelD) ,  subtitle(Model D)   coeflabels( complaint_Per1000="Complaint per1000" salience="Monthly Google trend" WaterDaysAllowedWeek="Water days allowed per week" ResidentialUse="% Residential use"  DMRating="Drought score" ) keep(complaint_Per1000       WaterDaysAllowedWeek ResidentialUse  salience        DMRating) order(complaint_Per1000       WaterDaysAllowedWeek ResidentialUse  salience        DMRating) xline(0,lpattern(dash))  scheme(s2mono)  title("")  legend(off)   levels(95)  











*********************************************************************************
*Robustness concerns
*********************************************************************************

*Interpretation
gen substantial_difference=CALCULATED_Monthly_Potable_2013*0.00555 
	   
egen substantial_difference_total=total(substantial_difference)  if ReportingMonth>=19950

sum substantial_difference_total

gen diff=substantial_difference_total/CALCULATEDTotalMonthlyPotable
list diff if SupplierName=="San Francisco Public Utilities Commission" & ReportingMonth>=19950




*Does partisan intensity improves voter turnout?  Nov. 2016  (Figure 3)
twoway scatter  PercentTurnout   party_comp_register  if ReportingMonth==20773  || lfitci PercentTurnout   party_comp_register  if ReportingMonth==20773 , graphregion(color(white)) scheme(s1mono) ytitle("% Voter turnout in 2016", size(small)) xtitle("Party competition index", size(small)) legend(off)   level(95) note("Note: 95% confidence interval") 
graph export "C:/Users/alz_1992/Desktop/Manny/CaliforniaConservation/20190306GreenPanopticon/Turnout vs party competition.pdf", as(pdf) replace

reg PercentTurnout   party_comp_register   StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating            MeanMedRatio   Density Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000   if ReportingMonth==20773 
predict xb if ReportingMonth==20773 ,xb
twoway scatter  xb   party_comp_register  if ReportingMonth==20773  || lfitci xb   party_comp_register  if ReportingMonth==20773 , graphregion(color(white)) scheme(s1mono) ytitle("Predicted % voter turnout in 2016", size(small)) xtitle("Party competition index", size(small)) legend(off)   level(95) note("Note: 95% confidence interval") 

esttab using reg5.csv, r2  aic bic label replace  mtitles("Model 3" "Model 4")   nodepvars nostar se(2)   parentheses  nogaps noeqlines nonumbers b(3)  nonotes compress
esttab using reg5-1.csv,p wide nogaps noparentheses replace 




*Correlation concern

reg complaint_Per1000 Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian    PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5, cluster(PWSID) 

*Cross validation

keep if  ReportingMonth >= 19950 & complaint_Per1000<=5

cvlasso  complaint_Per1000 Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating  i.ReportingMonth  , rolling origin(3) plotcv
cvlasso, lopt
cvlasso, lse


*Population density plot (Figure 5)
reg complaint_Per1000 Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   c.Density##c.Density  Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5, cluster(PWSID) 

margins, at(c.Density=(0(10)400))   
marginsplot, xlabel(0(5)400) yscale(range(0 47) titlegap(2)) scheme(s2mono) graphregion(color(white)) plot1opts(lpattern(longdash)) ciopts(recast(rline) fintensity(15) lpattern(dash_3dot)) ///
             addplot(histogram Density, percent  yaxis(2) ytitle("Percentage of observations", axis(2))  yscale(alt axis(2)) below ///
    bin(20) bcolor(gs12%30) lpattern(solid) lwidth(0.1) msymbol(none) mlabel(pipe) legend(off)) ///
	note("Note: 95% confidence interval") ///
	ytitle("Complaints per 1000 population", axis(1))  xtitle("Population density") title("")  ///
	level(95)  saving(type2)
	
	
*lrtest

reg complaint_Per1000   StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating   i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5
estimates store ModelA

reg complaint_Per1000  MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5
estimates store ModelB

reg complaint_Per1000 Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5 
estimates store ModelC

lrtest ModelA ModelB
lrtest ModelB ModelC	
	

	
*Alternative measure for party competition

gen party_comp_vote=1-abs((DemVote2016-RepVote2016)/TotalVote)
sum party_comp_vote
twoway scatter  PercentTurnout   party_comp_vote  if ReportingMonth==20773  || lfitci PercentTurnout   party_comp_vote  if ReportingMonth==20773 , graphregion(color(white)) scheme(s1mono) ytitle("% Voter turnout in 2016", size(small)) xtitle("Party competition index (vote share 2016)", size(small)) legend(off)   level(95) note("Note: 95% confidence interval") 
	
reg complaint_Per1000 Muni  Spdist party_comp_vote PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5, cluster(PWSID) 
estimates store ModelC

test Muni=Spdist



*F-test  
reg complaint_Per1000   StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating   i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5
estimates store ModelA

reg complaint_Per1000  MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5
estimates store ModelB

reg complaint_Per1000 Muni  Spdist party_comp_register PercentTurnout salience MeanMedRatio   Density Density2 Diversity   PercHisp PercBlack PercAsian  PerctBach  PerctPov medianincomehouse_1000  StatemandatedConservationStan2 WaterDaysAllowedWeek ResidentialUse groundw purchasedwater DMRating             i.ReportingMonth  if ReportingMonth>=19950 & complaint_Per1000<=5
estimates store ModelC
	
ftest ModelA ModelB
ftest ModelB ModelC		
